package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.app.Device;
import com.ruoyi.system.mapper.CommunityMapper;
import com.ruoyi.system.mapper.app.DeviceMapper;
import com.ruoyi.system.mapper.app.OrderMapper;
import com.ruoyi.system.mapper.app.RechargeOrderMapper;
import com.ruoyi.system.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.ListResourceBundle;
import java.util.Map;

@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    DeviceMapper deviceMapper;
    @Autowired
    CommunityMapper communityMapper;
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    RechargeOrderMapper rechargeOrderMapper;

    @Override
    public Map indexInfoCount() {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        if (sysUser.isAdmin()) {
            return communityMapper.indexInfoCount(null);
        }else {
            return communityMapper.indexInfoCount(sysUser.getUserId());
        }

    }

    @Override
    public List<Map> indexDeviceDistribute() {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        if (sysUser.isAdmin()) {
            return deviceMapper.indexDeviceDistribute(null);
        }else {
            return deviceMapper.indexDeviceDistribute(sysUser.getUserId());
        }
    }

    @Override
    public Map indexDevice() {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        if (sysUser.isAdmin()) {
            return deviceMapper.indexDevice(null);
        }else {
            return deviceMapper.indexDevice(sysUser.getUserId());
        }
    }

    @Override
    public Map indexHole() {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        if (sysUser.isAdmin()) {
            return deviceMapper.indexHole(null);
        }else {
            return deviceMapper.indexHole(sysUser.getUserId());
        }
    }

    @Override
    public List<Map> chargeCurve(String month,Long communityId) {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        if (sysUser.isAdmin()) {
            return orderMapper.chargeCurve(month,null,null);
        }else {
            return orderMapper.chargeCurve(month,sysUser.getUserId(),communityId);
        }
    }

    @Override
    public List<Map> rechargeCurve(String month,Long communityId) {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        if (sysUser.isAdmin()) {
            return rechargeOrderMapper.rechargeCurve(month,null,null);
        }else {
            return rechargeOrderMapper.rechargeCurve(month,sysUser.getUserId(),communityId);
        }
    }

    @Override
    public Map dayOrderCount(Integer type) {
        return rechargeOrderMapper.dayOrderCount(type,SecurityUtils.getLoginUser().getUser().getUserId());
    }

    @Override
    public Map indexData() {
        return rechargeOrderMapper.indexData(SecurityUtils.getLoginUser().getUser().getUserId());
    }

    @Override
    public List<Map> deviceUseRank(Long communityId,String month) {
        return rechargeOrderMapper.deviceUseRank(communityId,SecurityUtils.getLoginUser().getUser().getUserId(), month);
    }

    @Override
    public Map consumptionPie(String month) {
        return rechargeOrderMapper.consumptionPie(SecurityUtils.getLoginUser().getUser().getUserId(), month);
    }

    @Override
    public List<Map> orderCountLine(Integer month) {
        return rechargeOrderMapper.orderCountLine(month,SecurityUtils.getLoginUser().getUser().getUserId());
    }
}
